package com.binbinyl.model.remote

import android.content.Context
import com.binbinyl.BuildConfig
import com.binbinyl.helper.network.NetProvider
import com.binbinyl.helper.network.RequestHandler
import com.franmontiel.persistentcookiejar.PersistentCookieJar
import com.franmontiel.persistentcookiejar.cache.SetCookieCache
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor
import okhttp3.CookieJar
import okhttp3.Interceptor
import okhttp3.OkHttpClient

/**
 * 默认的 NetProvider
 */
open class DefaultNetProvider(private val mContext: Context) : NetProvider {

    override fun configInterceptors(): Array<Interceptor>? {
        return null
    }

    override fun configHttps(builder: OkHttpClient.Builder) {

    }

    override fun configCookie(): CookieJar? {
        return PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(mContext))
    }

    override fun configHandler(): RequestHandler? {
        return DefaultRequestHandler()
    }

    override fun configConnectTimeoutSecs(): Long {
        return CONNECT_TIME_OUT
    }

    override fun configReadTimeoutSecs(): Long {
        return READ_TIME_OUT
    }

    override fun configWriteTimeoutSecs(): Long {
        return WRITE_TIME_OUT
    }

    override fun configLogEnable(): Boolean {
        return BuildConfig.DEBUG
    }

    companion object {
        const val CONNECT_TIME_OUT: Long = 20
        const val READ_TIME_OUT: Long = 180
        const val WRITE_TIME_OUT: Long = 30
    }
}